// upload-worker.js
self.importScripts('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js');


self.onmessage = async (e) => {
  const { chunk, chunkIndex, fileHash, fileName } = e.data;

  const formData = new FormData();
  formData.append('file', chunk);
  formData.append('hash', `${fileHash}-${chunkIndex}`);
  formData.append('fileName', fileName);

  try {
    const response = await axios.post(
      'http://192.168.2.198:3000/api/common/file/uploadFile?fileId=a003cde7-95a0-45ba-bab1-ef690a3ae552',
      formData,
      {
        timeout: 3000,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
    )


    const result = await response.json();
    self.postMessage({ chunkIndex, success: true, result });
  } catch (error) {
    self.postMessage({ chunkIndex, success: false, error: error.message });
  }
};